#include "stdafx.h"
#include "Rect.h"

CStdRect::CStdRect()
{
	left = top = right = bottom = 0;
}

CStdRect::CStdRect(const RECT& src)
{
	left = src.left;
	top = src.top;
	right = src.right;
	bottom = src.bottom;
}

CStdRect::CStdRect(int iLeft, int iTop, int iRight, int iBottom)
{
	left = iLeft;
	top = iTop;
	right = iRight;
	bottom = iBottom;
}

int CStdRect::GetWidth() const
{
	return right - left;
}

int CStdRect::GetHeight() const
{
	return bottom - top;
}

void CStdRect::Empty()
{
	left = top = right = bottom = 0;
}

void CStdRect::Join(const RECT& rc)
{
	if( rc.left < left ) left = rc.left;
	if( rc.top < top ) top = rc.top;
	if( rc.right > right ) right = rc.right;
	if( rc.bottom > bottom ) bottom = rc.bottom;
}

void CStdRect::ResetOffset()
{
	::OffsetRect(this, -left, -top);
}

void CStdRect::Normalize()
{
	if( left > right ) { int iTemp = left; left = right; right = iTemp; }
	if( top > bottom ) { int iTemp = top; top = bottom; bottom = iTemp; }
}

void CStdRect::Offset(int cx, int cy)
{
	::OffsetRect(this, cx, cy);
}

void CStdRect::Inflate(int cx, int cy)
{
	::InflateRect(this, cx, cy);
}

void CStdRect::Deflate(int cx, int cy)
{
	::InflateRect(this, -cx, -cy);
}

void CStdRect::Union(CStdRect& rc)
{
	::UnionRect(this, this, &rc);
}
